#include <stdio.h>
#include <stdlib.h>

typedef struct linknode
{
	int data;
	struct linknode *next;
}link_node;

link_node *creat()
{
	link_node *H=(link_node *)malloc(sizeof(link_node));
	H->data=0;
	H->next=NULL;
	return H;
}

int insert(link_node *H,int newdata)
{
	link_node *p=(link_node *)malloc(sizeof(link_node));
	p->data=newdata;
	p->next=H->next;
	H->next=p;

	return 0;
}

int view(link_node *H)
{
	link_node *p=H;
	while(p->next!=NULL)
	{
		p=p->next;
		printf("%d ",p->data);
	}
	putchar(10);
	return 0;
}

int myoperation(link_node *H)
{
//	link_node *p=(link_node *)malloc(sizeof(link_node));

	link_node *p=H;
	link_node *p1=NULL;
	link_node *p2=NULL;

	while(p->next!=NULL&&p->next->next!=NULL)
	{
		p1=p->next;
		printf("p1:%d ",p1->data);
		p2=p->next->next;
		printf("p2:%d \n",p2->data);
		p1->next=p2->next;
		p2->next=p1;
		p->next=p2;
		printf("end1\n");
		p=p1;
		printf("p->data %d\n",p->data);
		/*
		if(p->next==NULL||p->next->next==NULL)
		{
			printf("end\n");
			break;
		}
		*/

	}

	return 0;
}
int main(int argc, const char *argv[])
{
	link_node *H=creat();
//	insert(H,4);
	insert(H,3);
	insert(H,2);
	insert(H,1);
	view(H);

	myoperation(H);
	view(H);
	return 0;
}
